<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="JinYan&#39;s blog">
  <meta name="keyword" content="hexo-theme, vuejs">
  
    <link rel="shortcut icon" href="/blog/css/images/logo.jpg">
  
  <title>
    
      check_nginx.sh | SanYuanEmpire
    
  </title>
  <link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdn.bootcss.com/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdn.bootcss.com/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/blog/css/style.css">
<link rel="stylesheet" href="/blog/css/plugins/gitment.css">
  <script src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdn.bootcss.com/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdn.bootcss.com/nprogress/0.2.0/nprogress.min.js"></script>
  <script src="/blog/js/qrious.js"></script>
<script src="/blog/js/gitment.js"></script>
  
  
    <!-- MathJax support START -->
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <!-- MathJax support END -->
  


</head>
<div class="wechat-share">
  <img src="/css/images/logo.jpg" />
</div>

  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/blog/">
      <div class="logo"></div>
      <span>SanYuanEmpire</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/blog/" class="item-link">Home</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/blog/archives/" class="item-link">Archives</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/blog/" class="menu-link">Home</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/blog/archives/" class="menu-link">Archives</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>check_nginx.sh</h2>
  <p class="post-date">2018-09-05</p>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br></pre></td><td class="code"><pre><span class="line">#!/bin/bash</span><br><span class="line">echo method1------------------------------------</span><br><span class="line">if [ `netstat -lnt|grep -w 80|awk -F &quot;[ :]+&quot; &apos;&#123;print $5&#125;&apos;` -eq 80 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method2------------------------------------</span><br><span class="line">if [ `netstat -lnt|grep -w 80|wc -l` -gt 0 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method3------------------------------------</span><br><span class="line">if [ `netstat -lnt|grep nginx|wc -l` -gt 0 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method4------------------------------------</span><br><span class="line">if [ `ss -lntup|grep nginx|wc -l` -gt 0 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method5------------------------------------</span><br><span class="line">if [ `ss -lntup|grep -w 80|wc -l` -gt 0 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method6------------------------------------</span><br><span class="line">if [ `lsof -i tcp:80|wc -l` -gt 0 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method7------------------------------------</span><br><span class="line">[ `rpm -eq nmap|wc -l` -lt 1 ] &amp;&amp; yum install nmap -y &amp;&gt;/dev/null</span><br><span class="line">if [ `nmap 127.0.0.1 -p 80 &amp;2&gt;/dev/null|grep open|wc -l` -gt 0 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method7------------------------------------</span><br><span class="line">if [ `echo -e &quot;\n&quot;|telnet 127.0.0.1 80 2&gt;/dev/null|grep Connected|wc -l` -gt 0]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method8------------------------------------</span><br><span class="line">[ `rpm -qa nc|wc -l` -lt 1 ] &amp;&amp; yum install nc -y &amp;&gt;/dev/null</span><br><span class="line">if [ `nc -w 2 127.0.0.1 80 &amp;&gt;/dev/null&amp;&amp;echo ok|grep ok|wc -l` -gt 0 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method9------------------------------------</span><br><span class="line">if [ `ps -ef|grep nginx|grep -v grep|wc -l` -ge 1 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method10------------------------------------</span><br><span class="line">if [ `ps -C nginx --no-header|wc -l` -gt 0 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method11------------------------------------</span><br><span class="line">if [[ `curl -I -s -o /dev/null -w &quot;%&#123;http_code&#125;\n&quot; http://127.0.0.1` =~ [23]0[012] ]]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method12------------------------------------</span><br><span class="line">if [ `curl -I http://127.0.0.1 &amp;2&gt;/dev/null|head -1|egrep &quot;200|302|301&quot;|wc -l` -eq 1 ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">echo method13------------------------------------</span><br><span class="line">if [ &quot;`curl -I http://127.0.0.1`&quot; = &quot;oldboy&quot; ]</span><br><span class="line">then</span><br><span class="line"> echo &quot;Nginx is Running.&quot;</span><br><span class="line">else</span><br><span class="line"> echo &quot;Nginx is Stopped.&quot;</span><br><span class="line"> /etc/sbin/nginx</span><br><span class="line">fi</span><br></pre></td></tr></table></figure>
</section>
    <!-- Tags START -->
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/blog/2018/09/05/check-memcached-sh/">
        <span class="nav-arrow">← </span>
        
          check_memcached.sh
        
      </a>
    
    
      <a class="nav-right" href="/blog/2018/09/05/check-opt-sh/">
        
          check_opt.sh
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    
      <!-- No Comment -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
    <strong class="toc-title">Catalog</strong>
    
      <ol class="nav">none</ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'git@gitee.com:sanyuanempire/blog.git/2018/09/05/check-nginx-sh/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

     // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()
        
        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })

    // qrcode
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });

    // gitment
    var gitmentConfig = "";
    if (gitmentConfig !== 'undefined') {
      var gitment = new Gitment({
        id: "check_nginx.sh",
        owner: "",
        repo: "",
        oauth: {
          client_id: "",
          client_secret: ""
        },
        theme: {
          render(state, instance) {
            const container = document.createElement('div')
            container.lang = "en-US"
            container.className = 'gitment-container gitment-root-container'
            container.appendChild(instance.renderHeader(state, instance))
            container.appendChild(instance.renderEditor(state, instance))
            container.appendChild(instance.renderComments(state, instance))
            container.appendChild(instance.renderFooter(state, instance))
            return container;
          }
        }
      })
      gitment.render(document.getElementById('comments'))
    }
  })();
</script>

<script>
  var disqus_shortname = '';
  
  var disqus_url = 'git@gitee.com:sanyuanempire/blog.git/2018/09/05/check-nginx-sh/';
  
  (function(){
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true;
    dsq.src = '//go.disqus.com/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>

    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
  <p class="copyright">
    &copy; 2018 | Proudly powered by <a href="https://sanyuanempire.gitee.io/blog" target="_blank">JinYan</a>
    <br>
    Theme by <a href="https://sanyuanempire.gitee.io/blog">JinYan</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("//cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("//cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>
<!-- Baidu Tongji -->

<script src="/blog/js/script.js"></script>

  </body>
</html>